package com.study.dialogutilsample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.study.dialoglib.CommonDialog;
import com.study.dialogutilsample.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity implements CommonDialog.OnBtnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.tvHello.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new CommonDialog
                        .Builder()
                        .setTitle("提示")
                        .setContent("提示消息")
                        .setCancelBtn("cancel")
                        .setConfirmBtn("confirm")
                        .setOnBtnClickListener(MainActivity.this)
                        .build(MainActivity.this)
                        .show();
            }
        });
    }

    @Override
    public void onClick(DialogInterface dialog, CommonDialog.CLICK_TYPE type, String msg) {
        dialog.cancel();
        if (type == CommonDialog.CLICK_TYPE.CONFIRM) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
        }
    }
}